function recursiveFindFrame(name,from,path)
{
	if(from==null)return null;
	var x=from.getElementsByTagName("frame");
	for(var i=0;i<x.length;i++)
  	{
		if(x[i].name==name)return x[i].contentDocument;
		var y=recursiveFindFrame(name,x[i].contentDocument,path+"\\"+[i].name);
		if(y!=null)return y;
	}
	return null;
}
function replaceToken(sOrg,table)
{
	for(var x in table)
		sOrg=sOrg.split("%"+x+"%").join(table[x])
	return sOrg
}
function start(){
	var sTemplate=[
		"Summary : %title%",
		"",
		"Tracker Id: %id%",
		"",
		"Reviewed By : ",
		"",
		"Description : ",
	].join('\n')

	var dFrame=document;
	var oTitle=null;
	
	while(true){
		oTitle=$('#itemtitle',dFrame)[0]
		if(oTitle!=null)break;
		dFrame=recursiveFindFrame("Detail",dFrame,"");
	}
	
	if($('#p4SummaryCloseA',dFrame).length>0)
	{
		$('#p4SummaryCloseA',dFrame).click()
		$('.frmBtn[value*=Create Perforce Job]',dFrame).css('font-size','')
		return
	}
	
	
	//parse tracker general info
	oTrackerInfo={
		id:oTitle.childNodes[3].textContent.replace(":",""),
		title:oTitle.childNodes[4].data
	}
	
	var oMainDiv=$('<div style=padding:10px></div>')
	oMainDiv.append(
	"<textarea id='p4SummaryTextArea' style='width:100%;height:150px'></textarea>"
	+"<button id='p4SummaryCloseA' >close</button>"
	)
	oMainDiv.appendTo($(oTitle))
	
	//fill textarea content
	var textArea=dFrame.getElementById('p4SummaryTextArea');
	textArea.value=replaceToken(sTemplate,oTrackerInfo)
	textArea.focus();
   	textArea.select();
	var a=dFrame.getElementById('p4SummaryCloseA');
	a.onclick=function()
	{
		oTitle.removeChild(oMainDiv[0])
		$('.frmBtn[value*=Create Perforce Job]',dFrame).css('font-size','')
	}
	
	//check perforce job created
	var oP4Job=$('span.F409:first',dFrame)
	if(oP4Job.text().length<3)
	{
		//not created before
		$('.frmBtn[value*=Create Perforce Job]',dFrame).css('font-size','20pt')
	}
	else
	{
		var sP4Job
		if(oP4Job.children('.issuePanelContainer').length>0){
			//has submitted
			sP4Job=oP4Job.children('.issuePanelContainer b:first').text().split(':')[1]
		}else{
			//not submit any changelist.
			sP4Job=oP4Job.text().split(':')[1].replace(' ','').split(' ').join('_')
		}
		oMainDiv.append('<span style=padding:10px>'+sP4Job+'</span>')
	}
	
}
start();